package config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import sim.util.Double2D;


public class IntersectionSpecification {

	public double x;
	public double y;
	
	/**
	 * 
	 * @param x
	 * @param y
	 */
	protected IntersectionSpecification(double x, double y) {
		super();
		this.x = x;
		this.y = y;
	}

	/**
	 * 
	 * @param junction
	 * @return
	 */
	public static IntersectionSpecification getCoordinatesByID(int junction){
		switch (junction) {
		case 0:
			return new IntersectionSpecification(10, 10);
		case 1:
			return new IntersectionSpecification(60, 10);
		case 2:
			return new IntersectionSpecification(110, 10);
		case 3:
			return new IntersectionSpecification(10, 60);
		case 4:
			return new IntersectionSpecification(10, 110);
		case 5:
			return new IntersectionSpecification(60, 60);
		case 6:
			return new IntersectionSpecification(60, 110);
		case 7:
			return new IntersectionSpecification(110, 60);
		case 8:
			return new IntersectionSpecification(110, 110);
		default:
			System.err.println("ERROR: Coordinates for intersection " + junction + " not specified!");
			return new IntersectionSpecification(0, 0);
		}
	}

	/**
	 * @param myID
	 * @return
	 */
	public static ArrayList<String> getEdgeInfos(){
		ArrayList<String> edgeInfos = new ArrayList<String>();

		// Formatting instruction: STARTNODE; DESTINATIONNODE
		// Sender = Node 0
		edgeInfos.add("0; 1");
		edgeInfos.add("0; 3");
		edgeInfos.add("0; -110");
		edgeInfos.add("0; -115");
		
		// Sender = Node 1
		edgeInfos.add("1; 0");
		edgeInfos.add("1; 2");
		edgeInfos.add("1; 5");
		edgeInfos.add("1; -120");
		
		// Sender = Node 2
		edgeInfos.add("2; 1");
		edgeInfos.add("2; 7");
		edgeInfos.add("2; -125");
		edgeInfos.add("2; -130");
		
		// Sender = Node 3
		edgeInfos.add("3; 0");
		edgeInfos.add("3; 4");
		edgeInfos.add("3; 5");
		edgeInfos.add("3; -140");
		
		// Sender = Node 4
		edgeInfos.add("4; 3");
		edgeInfos.add("4; 6");
		edgeInfos.add("4; -145");
		edgeInfos.add("4; -150");
		
		
		// Sender = Node 5
		edgeInfos.add("5; 1");
		edgeInfos.add("5; 3");
		edgeInfos.add("5; 6");
		edgeInfos.add("5; 7");
		
		
		// Sender = Node 6
		edgeInfos.add("6; 4");
		edgeInfos.add("6; 5");
		edgeInfos.add("6; 8");
		edgeInfos.add("6; -155");
		
		
		// Sender = Node 7
		edgeInfos.add("7; 2");
		edgeInfos.add("7; 5");
		edgeInfos.add("7; 8");
		edgeInfos.add("7; -135");
		
		
		// Sender = Node 8
		edgeInfos.add("8; 6");
		edgeInfos.add("8; 7");
		edgeInfos.add("8; -160");
		edgeInfos.add("8; -165");
		
		
		return edgeInfos;
	}
	
	public static List<Integer> getNeighbourIDs(int myID){
		switch (myID) {
		case 0:
			return Arrays.asList(-110, 1, 3, -115);
		case 1:
			return Arrays.asList(-120, 0, 2, 5);
		case 2:
			return Arrays.asList(-130, -125, 1, 7);
		case 3:
			return Arrays.asList(-140, 0, 4, 5);
		case 4:
			return Arrays.asList(-150, -145, 3, 6);
		case 5:
			return Arrays.asList(1, 3, 6, 7);
		case 6:
			return Arrays.asList(4, 5, 8, -155);
		case 7:
			return Arrays.asList(-135, 2, 5, 8);
		case 8:
			return Arrays.asList(-160, 6, 7, -165);
		default:
			System.err.println("ERROR: Coordinates for intersection " + myID + " not specified!");
			return null;
		}
	}
	
	/**
	 * Method extracts a Double2D position from the intersection coordinates
	 * @param coord
	 * @return
	 */
	public static Double2D getDouble2DFromIntersectionCoordinates(IntersectionSpecification coord){
		return new Double2D(coord.x, coord.y);
	}
}
